package com.magictower.primary.db.dao;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * @author kejunzhan
 * @since 2017/12/21
 */

public class AntivirusDao {
    public static final String VIRUS_DB = "/data/data/com.magictower.primary/files/antivirus.db";

    /**
     * 检查当前的md5值是否在病毒数据库
     * @param md5
     * @return
     */
    public String checkFileVirus(String md5){
        String res = null;
        SQLiteDatabase db = SQLiteDatabase.openDatabase(VIRUS_DB, null, SQLiteDatabase.OPEN_READONLY);
        Cursor cursor = db.rawQuery("select desc from datable where md5 = ?", new String[]{md5});
        while (cursor.moveToNext()) {
            res = cursor.getString(0);
        }
        cursor.close();
        db.close();
        return res;
    }

    /**
     * 添加病毒数据库
     * @param md5  特征码
     * @param desc 描述信息
     */
    public void addVirus(String md5,String desc){
        SQLiteDatabase db = SQLiteDatabase.openDatabase(VIRUS_DB, null, SQLiteDatabase.OPEN_READWRITE);
        ContentValues values = new ContentValues();
        values.put("md5", md5);
        values.put("desc", desc);
        values.put("type", 6);
        values.put("name", "Android.Troj.AirAD.a");
        db.insert("datable", null, values);
        db.close();
    }
}
